<?php
/***
 * Description:this is description
 * Date: 2021/4/21
 * Time: 4:33 下午
 * Author gan
 */

require "../vendor/autoload.php";

go(function () {
    $config = array(
        'host'       => "127.0.0.1",
        'port'       => 3306,
        'database'   => 'tpshop',
        'username'   => 'root',
        'password'   => '123456',
        'charset'    => 'utf8mb4',
        'unixSocket' => null,
        'options'    => [
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        ],
        'size'       => 10
    );

    $db = new \EasyDB\Db\EasyPdo($config);
    $db->get("test", ["id", "name"]);
    $db->select("test", "*");
    $db->insert("test", ["name" => "test"]);
    $db->update("test", ["name" => "test2"], ["id" => 1]);
    $db->delete("test", ["id" => 1]);
});


go(function () {
    $conf  = [
        'host'     => 'localhost',
        'port'     => 6379,
        'auth'     => '7GNR8pI5LOlh',
        'db_index' => 15,
        'time_out' => 3,
        'size'     => 10,
    ];
    $redis = new \EasyDB\RedisDb\EasyRedis($conf, "master");
    $redis->set('key', json_encode(["code" => 1, "message" => 'key:---' . time()]));
    $redis->get('key');

    $rand = $redis->lock("lock:api");
    var_dump($rand);
    var_dump($redis->unlock("lock:api", $rand));

    $a = $redis->lockFunction("lock-fuc", function () {
        return 1;
    });
    var_dump($a);
});
